package com.kingyea.mobilepolice.apimanage.paraminfo.controller;

import com.kingyea.mobilepolice.apimanage.log.OperateType;
import com.kingyea.mobilepolice.apimanage.log.OperationLogAnnotation;
import com.kingyea.mobilepolice.apimanage.paraminfo.bean.ParamInfo;
import com.kingyea.mobilepolice.apimanage.paraminfo.service.ParamInfoService;
import com.kingyea.mobilepolice.apimanage.utils.GlobalVar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ParamInfo 控制层
 * @date Created in 2018-03-11 11:20:05
 */
@RequestMapping(value = "/paramInfo")
@RestController
public class ParamInfoController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ParamInfoController.class);

    @Autowired
    private ParamInfoService paramInfoService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @OperationLogAnnotation(operateName = "查询全部接口参数", operateType = OperateType.SELECT, module = "paraminfo")
    @RequestMapping(method = RequestMethod.GET)
    public Object list() throws Exception {
        System.out.println(GlobalVar.inside);
        System.out.println(GlobalVar.getMqBrokerUrl());
        System.out.println(GlobalVar.getMqUsername());
        return paramInfoService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @OperationLogAnnotation(operateName = "通过ID查找接口参数", operateType = OperateType.SELECT, module = "paraminfo")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Object detail(@PathVariable Integer id) throws Exception {
        return paramInfoService.getById(id);
    }

    /**
     * 创建
     *
     * @param paramInfo
     * @return
     */
    @OperationLogAnnotation(operateName = "创建接口参数", operateType = OperateType.INSERT, module = "paraminfo")
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody ParamInfo paramInfo) throws Exception {
        return paramInfoService.save(paramInfo);
    }

    /**
     * 更新
     *
     * @param paramInfo
     * @return
     */
    @OperationLogAnnotation(operateName = "更新接口参数", operateType = OperateType.UPDATE, module = "paraminfo")
    @RequestMapping(method = RequestMethod.PUT)
    public Object update(@RequestBody ParamInfo paramInfo) throws Exception {
        return paramInfoService.update(paramInfo);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @OperationLogAnnotation(operateName = "删除接口参数", operateType = OperateType.DELETE, module = "paraminfo")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Object delete(@PathVariable Integer id) throws Exception {
        return paramInfoService.deleteById(id);
    }

}
